package com.example.zookpeeper.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class CuratorConfig {
    @Bean
    public CuratorFramework createClient() {

        log.info("CuratorFramework 创建！！！");
        CuratorFramework build = CuratorFrameworkFactory.builder()
                .connectString("106.52.34.18:12181")
                .sessionTimeoutMs(3000)
                .connectionTimeoutMs(5000)
                // 重试机制
                .retryPolicy(new ExponentialBackoffRetry(1000, 3))
                .build();
        build.start();
        try {
            build.blockUntilConnected();
        } catch (InterruptedException e) {
        }

        return build;
    }
}
